<script>
  var minOperations = function (nums, numsDivide) {
    const obj = {};
    let ans = 0;
    nums.forEach(num => obj[num] ? obj[num]++ : obj[num] = 1);
    const keys = Object.keys(obj).sort((a, b) => a - b);
    for (let i = 0; i < keys.length; i++) {
      const num = Number(keys[i])
      let j = 0;
      for (; j < numsDivide.length; j++) {
        const item = numsDivide[j];
        if (item % num != 0) {
          ans += obj[num];
          break;
        }
      }
      if(j===numsDivide.length){
        return ans;
      }
    }
    return -1;
  };
  console.log(minOperations([2, 3, 2, 4, 3], [9, 6, 9, 3, 15]));
</script>